﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class allNews1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        dlBind();
    }

    public void dlBind()
    {
        SqlConnection sqlcon;
        string strCon = System.Configuration.ConfigurationManager.ConnectionStrings["decheatConnectionString"].ToString();
        int curpage = Convert.ToInt32(this.labPage.Text);
        PagedDataSource ps = new PagedDataSource();
        sqlcon = new SqlConnection(strCon);
        sqlcon.Open();
        string sqlstr = "SELECT id, topicid, headtitle, pretitle, title, titlecolor, titlefont, subtitle, newscontent, keyword, pagetype, autopagewordnumber, photos, Priority, newsfrom, sort, userid, username, time, subclassid, subclassname, mainclassid, mainclassname, hits, zhaiyao, xiangguan, url, [top], Score, Recommended, readstate, Delete_flag FROM dbo.Dyh_News where Delete_flag=0 order by subclassid ,time desc";
        SqlDataAdapter MyAdapter = new SqlDataAdapter(sqlstr, sqlcon);
        DataSet ds = new DataSet();
        MyAdapter.Fill(ds, "id");
        ps.DataSource = ds.Tables["id"].DefaultView;
        ps.AllowPaging = true; //是否可以分页  
        ps.PageSize = 5; //显示的数量  
        ps.CurrentPageIndex = curpage-1 ; //取得当前页的页码  
        this.lnkbtnUp.Enabled = true;
        this.lnkbtnNext.Enabled = true;
        this.lnkbtnBack.Enabled = true;
        this.lnkbtnOne.Enabled = true;
        if (curpage == 1)
        {
            this.lnkbtnOne.Enabled = false;//不显示第一页按钮  
            this.lnkbtnUp.Enabled = false;//不显示上一页按钮  
        }
        if (curpage == ps.PageCount)
        {
            this.lnkbtnNext.Enabled = false;//不显示下一页  
            this.lnkbtnBack.Enabled = false;//不显示最后一页  
        }
        this.labBackPage.Text = Convert.ToString(ps.PageCount);
        this.DataList1.DataSource = ps;
        this.DataList1.DataKeyField = "id";
        this.DataList1.DataBind();
        sqlcon.Close();
    }
    protected void lnkbtnOne_Click(object sender, EventArgs e)
    {
        this.labPage.Text = "1";
        this.dlBind();
    }
    protected void lnkbtnUp_Click(object sender, EventArgs e)
    {
        this.labPage.Text = Convert.ToString(Convert.ToInt32(this.labPage.Text) - 1);
        this.dlBind();
    }
    protected void lnkbtnNext_Click(object sender, EventArgs e)
    {
        this.labPage.Text = Convert.ToString(Convert.ToInt32(this.labPage.Text) + 1);
        this.dlBind();
    }
    protected void lnkbtnBack_Click(object sender, EventArgs e)
    {
        this.labPage.Text = this.labBackPage.Text;
        this.dlBind();
    }
}